﻿using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UniLua;
using System;

public class tester : MonoBehaviour, Swift.ILog {

    public CombatMgr CbtMgr;

    public void Debug(string str)
    {
        UnityEngine.Debug.Log(str);
    }

    public void Error(string str)
    {
        UnityEngine.Debug.LogError(str);
    }

    public void Info(string str)
    {
        UnityEngine.Debug.Log(str);
    }

    public void Warn(string str)
    {
        UnityEngine.Debug.LogWarning(str);
    }

    // Use this for initialization
    void Start () {
        UniLua.Tools.ULDebug.Logger = this;
        UniLua.LuaFile.LUA_ROOT = Path.Combine("Assets/Resources", "LuaScripts");
        UniLua.LuaPkgLib.ExtraLoader = LoadLuaFromResources;
    }

    static int LoadLuaFromResources( ILuaState lua )
    {
        string name = lua.L_CheckString(1);
        var luaScript = Resources.Load("LuaScripts/" + name + ".lua") as TextAsset;
        if (luaScript != null && lua.L_LoadString(luaScript.text) == ThreadStatus.LUA_OK)
        {
            lua.PushString(name);
            return 2;
        }
        else
            return 1;
    }

    // Update is called once per frame
    void Update () {
		
	}

    // 刷新脚本，并重启异常战斗
    public void OnRestart()
    {
        CbtMgr.CreateNewCombat("tester");
    }
}
